﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OcrWinForm.VO
{
    public class OCRVO
    {
        public List<TxetItem> Items { get; set; }
    }

    public class TxetItem
    {
        public List<Point> BoxPoints { get; set; }
        public double Score { get; set; }
        public string Text { get; set; }
        public int cls_label { get; set; }
        public double cls_score { get; set; }

        public RectangleF ToRectangleF()
        {
            if (BoxPoints == null || BoxPoints.Count < 4)
            {
                throw new InvalidOperationException("BoxPoints must contain at least 4 points to form a rectangle.");
            }

            // 找到BoxPoints中的最小和最大X、Y坐标
            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float maxX = float.MinValue;
            float maxY = float.MinValue;

            foreach (var point in BoxPoints)
            {
                if (point.X < minX) minX = point.X;
                if (point.Y < minY) minY = point.Y;
                if (point.X > maxX) maxX = point.X;
                if (point.Y > maxY) maxY = point.Y;
            }

            // 计算矩形的左上角坐标和宽高
            float width = maxX - minX;
            float height = maxY - minY;

            return new RectangleF(minX, minY, width, height);
        }
    }
}
